package ua.maxicash.vo;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "Employer")
@PrimaryKeyJoinColumn(name = "ID_USER")
@JsonIgnoreProperties({"works", "password", "avatar", "likes"})
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Employer extends SystemUser {

    @Column(name = "ORGANIZATION")
    private String organization;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name = "ID_USER")
    private Set<Work> works;

    @ManyToMany
    @JoinTable(name = "Employer_JobType", joinColumns = {@JoinColumn(name = "ID_USER")},
            inverseJoinColumns = {@JoinColumn(name = "ID_JOB")})
    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(value = {org.hibernate.annotations.CascadeType.SAVE_UPDATE})
    @Size(min = 1)
    private Set<JobType> jobTypes = new HashSet<JobType>();

    public Employer() {
    }

    public Set<JobType> getJobTypes() {
        return jobTypes;
    }

    public void setJobTypes(Set<JobType> jobTypes) {
        this.jobTypes = jobTypes;
    }

    public Set<Work> getWorks() {
        return works;
    }

    public void setWorks(Set<Work> works) {
        this.works = works;
    }

    public String getOrganization() {
        return organization;
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

}